package io.renren.modules.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.FyUsersEntity;
import io.renren.modules.sys.service.FyParentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-03-01 10:35:38
 */
@RestController
@RequestMapping("sys/fyparent")
public class FyParentController {
    @Autowired
    private FyParentService fyParentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:fyparent:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = fyParentService.queryListParent(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
    @RequiresPermissions("sys:fyparent:info")
    public R info(@PathVariable("userId") Integer userId){
        FyUsersEntity fyUsers = fyParentService.getById(userId);

        return R.ok().put("fyUsers", fyUsers);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:fyparent:save")
    public R save(@RequestBody FyUsersEntity fyUsers){
        fyParentService.save(fyUsers);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:fyparent:update")
    public R update(@RequestBody FyUsersEntity fyUsers){
        ValidatorUtils.validateEntity(fyUsers);
        fyParentService.updateById(fyUsers);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:fyparent:delete")
    public R delete(@RequestBody Integer[] userIds){
        fyParentService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

    /**
     * 查询所有用户信息
     */
    @RequestMapping("/alllist")
    @RequiresPermissions("sys:fyparent:alllist")
    public R alllist(){
        List<FyUsersEntity> alllist = fyParentService.list(new QueryWrapper<FyUsersEntity>());
        return R.ok().put("alllist", alllist);
    }

}
